<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 5. <对象(映射)&数组练习>转换数组
        const mapping = {
            shengjian: '生煎',
            baozi: '灌汤包',
            jiaozi: '水饺',
            burger: '汉堡',
        };
        const input = [
            {
                label: '生煎',
                value: '生煎',
            },
            {
                label: '灌汤包',
                value: '灌汤包',
            },
            {
                label: '水饺',
                value: '水饺',
            },
            {
                label: '汉堡',
                value: '汉堡',
            },
        ];
        const output = [
            {
                label: '生煎',
                value: 'shengjian',
            },
            {
                label: '灌汤包',
                value: 'baozi',
            },
            {
                label: '水饺',
                value: 'jiaozi',
            },
            {
                label: '汉堡',
                value: 'burger',
            },
        ];


        // ⭐
        function transform (input, mapping) {
            // 反转映射
            const newMapping = {};
            for (const key in mapping) {
                newMapping[mapping[key]] = key;
            }
            // 映射数组
            return input.map((item) => ({
                ...item,                   //{label: '生煎', value: 'shengjian'}
                value: newMapping[item.value],// mapping['shengjian'] 覆盖掉...item里面的label
            }))   
        }
        console.log(transform(input, mapping));
    </script>
</body>
</html>